Depth first search
Number of Islands
leetcode algorithm depth first search
Comments CountProblem description
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Surrounded Regions
leetcode algorithm depth first search
Comments CountProblem description
Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.
Complete Binary Tree Inserter
binary tree depth first search
Comments CountProblem description
A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Smallest Subtree with all the Deepest Nodes (LC865)
leetcode algorithm binary tree depth first search
Comments CountProblem description
Given a binary tree rooted at root, the depth of each node is the shortest distance to the root.
All Nodes Distance K in Binary Tree (LC863)
leetcode algorithm depth first search binary tree
Comments CountProblem description
We are given a binary tree (with root node root), a target node, and an integer value K.
Sum of Distances in Tree (LC834)
leetcode algorithm depth first search tree
Comments CountProblem description
An undirected, connected tree with N nodes labelled 0…N-1 and N-1 edges are given.
Flip Binary Tree to Match Preorder Traversal (LC971)
depth first search preorder traversal binary tree
Comments CountProblem description
Given a binary tree with N nodes, each node has a different value from {1, …, N}.
Binary Tree Pruning (LC814)
leetcode algorithm binary tree depth first search post order traversal
Comments CountProblem description
We are given the head node root of a binary tree, where additionally every node’s value is either a 0 or a 1.
Insert into Binary Search Tree (LC701)
algorithm leetcode depth first search binary tree
Comments CountProblem description
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.
Print Binary Tree (LC655)
binary tree recursion depth first search leetcode algorithm
Comments CountProblem description
Print a binary tree in an m*n 2D string array following these rules:
Course Schedule II (LC210)
leetcode algorithm topological sort breadth first search depth first search
Comments CountProblem description
There are a total of n courses you have to take, labeled from 0 to n-1.
Course Schedule (LC207)
leetcode algorithm topological sort depth first search breadth first search
Comments CountProblem description
There are a total of n courses you have to take, labeled from 0 to n-1.
Find Duplicate Subtrees (LC652)
leetcode algorithm depth first search binary tree
Comments CountProblem description
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.
Sum of Left Leaves (LC404)
leetcode algorithm binary tree depth first search tree traversal
Comments CountProblem description
Find the sum of all left leaves in a given binary tree.